﻿Public Class xtf_LISTADOconfig_error_

    Public Overrides Sub IniciarLista()
        Try
            gdc_general.BeginUpdate()
            gdc_general.DataSource = dtt_DataTable
            'ulg_Lista.DisplayLayout.GroupByBox.Style = Infragistics.Win.UltraWinGrid.GroupByBoxStyle.Full

            'Creacion y carga de Cuentas
            dtt_DataTable.Columns.Add("Código")
            dtt_DataTable.Columns.Add("Titulo")
            dtt_DataTable.Columns.Add("Descripcion")
            dtt_DataTable.Columns.Add("Imagen")
            dtt_DataTable.Columns.Add("Botones")

            gdv_general.PopulateColumns(dtt_DataTable)

            Dim obj_config_error_ As New cls_config_error_
            If obj_config_error_.CargarTodos Then
                For Each config_error As cls_config_error_ In obj_config_error_.Items
                    AgregarItem(config_error)
                Next
            End If
            'ulg_Lista.DataBind()

            FiltrarColumnas()
            gdc_general.EndUpdate()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Overrides Sub bbi_Modificar_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) 'Handles bbi_modificar.ItemClick
        If ComprobarPermiso(PERMISOModificar) Then
            Try
                Dim barrio As Object 'New cls_barrio_
                barrio = Activator.CreateInstance(Type.GetType(Replace(Application.ProductName, " ", "_") & "." & Replace(Me.Name, "xtf_LISTADO", "cls_"), True, True))
                If gdv_general.SelectedRowsCount > 0 Then
                    If barrio.Buscar(gdv_general.GetDataRow(gdv_general.GetSelectedRows(0))("Código")) Then
                        bsi_estado.Caption = "Cargando..."
                        Application.DoEvents()
                        Dim ABM As Object 'New xtf_ABMbarrio
                        ABM = CType(Activator.CreateInstance(Type.GetType(Replace(Application.ProductName, " ", "_") & "." & Strings.Left(Replace(Me.Name, "xtf_LISTADO", "xtf_ABM"), Replace(Me.Name, "xtf_LISTADO", "xtf_ABM").Length - 1), True, True)), Form)
                        ABM.Modificar(barrio, Me, gdv_general.GetDataRow(gdv_general.GetSelectedRows(0)))
                        ABM.ControlarModificaciones(ABM.lac_general.items)
                        bsi_estado.Caption = "Listo"
                    End If
                End If

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Public Function AgregarItem(ByRef config_error As cls_config_error_) As DataRow
        Dim Row As DataRow = dtt_DataTable.NewRow

        Row("Código") = config_error.codigo
        Row("Titulo") = config_error.titulo
        Row("Descripcion") = config_error.descripcion
        Row("Imagen") = config_error.img
        Row("Botones") = config_error.botones


        dtt_DataTable.Rows.Add(Row)
        'ulg_Lista.Rows(ulg_Lista.Rows.Count - 1).Height = 19
        Return Row
    End Function

    Public Sub ModificarItem(ByRef config_error As cls_config_error_, ByRef ulg_row As DataRow)
        ulg_row("Código") = config_error.codigo
        ulg_row("Titulo") = config_error.titulo
        ulg_row("Descripcion") = config_error.descripcion
        ulg_row("Imagen") = config_error.img
        ulg_row("Botones") = config_error.botones
    End Sub

    Public Sub New()

        Me.Cursor = Cursors.WaitCursor
        InitializeComponent()
        PERMISONuevo = ""
        PERMISOModificar = ""
        PERMISOEliminar = ""
        PERMISOImprimir = ""
        bbi_Nuevo.Enabled = False
        bbi_eliminar.Enabled = False
        Me.Text = lbl_modulo.Text : lbl_modulodescripcion.Text = "Listado de " & lbl_modulo.Text & "."
        IniciarLista()
        Me.Cursor = Cursors.Default

    End Sub

End Class